package com.situ.day2;

import org.junit.Test;

public class Hello {

    public static void main(String[] args) {
        int num23$ = 2;
        // int 2num = 4;
        // 变量的命名：你想表达什么意思就起什么名字
        //变量 variable
        int age1 = 3;
        age1 = 34;
        //常量 值不能改变
        final int age2 = 23;
        //Cannot assign a value to final variable 'age2'
        //age2 = 24;

        byte b1 = 12;
        byte b2 = 127;
        //byte b3 = 128;
        byte b3 = -128;

        double d1 = 3.14;
        float f1 = 3.14f;

        char ch1 = 'a';
        char ch2 = '7';
        //char ch3 = '中';

        boolean boo1 = true;
        boolean boo2 = false;
    }

    /**
     * junit: java unit
     */
    @Test
    public void test1() {
        //1、从小到大自动类型转换
        //2、从大到小需要强制类型转换，可能会丢失精度(装水的杯子大小不一样)
        System.out.println("中国");
        char ch = 'a';//97
        System.out.println(ch);//a
        System.out.println(ch + 1);//97+1=98 从小到大自动类型转换
        System.out.println(ch + 2);//97+2=99
        System.out.println((char)(ch + 1));//b 从大到小强制类型转换
        System.out.println((char)(ch + 2));//c 从大到小强制类型转换

        double d = 3.14;
        int num = (int)d;
        System.out.println(num);//3

    }

    //运算符：
    @Test
    public void test2() {
        System.out.println("Hello.test2");
        int num1 = 3;
        int num2 = 5;
        int result = num1 + num2;
        System.out.println(result);
        System.out.println(num1 - num2);
        System.out.println(num1 * num2);
        System.out.println(num1 / num2);


        System.out.println(8 / 2);//4
        System.out.println(8 % 2);//0
        System.out.println(8 / 5);//1
        System.out.println(8 % 5);//3
    }

    @Test
    public void test3() {
        //++(自增1)    --(自减1)
        int i = 1;
        i++;//++i
        System.out.println(i);//2
        System.out.println(i++);//2
        System.out.println(i);//3
        System.out.println(++i);//4
    }

    @Test
    public void test4() {
        //比较运算符：>   <    >=     <=    !=
        //比较之后的结果只有两种情况：true、false，所以比较运算的结果是boolean类型
        System.out.println(3 >= 5);//false
        System.out.println(5 <= 10);//true
        int num1 = 3;
        int num2 = 5;
        System.out.println(num1 != num2);//true
    }

    // 逻辑运算符：&&      ||      ！    运算结果也是boolean类型
    // &&：两边的结果都是true，结果才是true
    // ||：两边只要有一个是true，结果就是true
    @Test
    public void test6() {
        int score1 = 78;
        int score2 = 390;
        boolean result1 = (score1 >= 60) && (score2 >= 400);
        System.out.println(result1);//false
        boolean result2 = (score1 >= 60) || (score2 >= 400);
        System.out.println(result2);//true

        //短路
        int num1 = 3;
        int num2 = 5;
        //&&短路
        System.out.println(num1 < 0 && num1++ < num2);//false
        System.out.println(num1);//3
        System.out.println(num2);//5

        //||短路
        System.out.println(num1 > 0 || num1++ < num2);//true
        System.out.println(num1);//3
        System.out.println(num2);//5

        //位运算
        System.out.println(3&5);
    }

}
